package me.zhengjie.modules.weixin.dto;

import me.zhengjie.modules.weixin.enums.WechatConfigEnums;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 微信公众号账号信息
 *
 */
public class WeChatAccount {

    private String appId;

    private String appSecret;

    private Integer authType = 1;

    private String token;

    private String encodingAESKey;

    private String accessToken;

    private String refreshToken;

    private List<WeChatPlatform> platform;

    private List<WeChatMessage> messages;

    public WeChatAccount() {

    }

    public WeChatAccount(String appId) {
        if (StringUtils.isNotBlank(appId)) {
            WechatConfigEnums wechatConfigEnums = WechatConfigEnums.getEnumsByAppid(appId);
            this.token = wechatConfigEnums.getToken();
            this.appId = wechatConfigEnums.getAppid();
            this.appSecret = wechatConfigEnums.getSecret();
        }
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }

    public Integer getAuthType() {
        return authType;
    }

    public void setAuthType(Integer authType) {
        this.authType = authType;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getEncodingAESKey() {
        return encodingAESKey;
    }

    public void setEncodingAESKey(String encodingAESKey) {
        this.encodingAESKey = encodingAESKey;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public List<WeChatPlatform> getPlatform() {
        return platform;
    }

    public void setPlatform(List<WeChatPlatform> platform) {
        this.platform = platform;
    }

    public WeChatPlatform getPlatform(String platformAppId) {
        return platform.parallelStream().filter(s -> s.getAppId().equals(platformAppId)).findFirst().orElse(null);
    }

    public List<WeChatMessage> getMessages() {
        return messages;
    }

    public void setMessages(List<WeChatMessage> messages) {
        this.messages = messages;
    }
}

